/*
 * @Description: 表格列配置
 * @Author: HuiSir<https://gitee.com/huisir001>
 * @Date: 2021-11-05 11:41:30
 * @LastEditTime: 2025-09-29 11:39:10
 */
import { defineTableCols } from "@/components/TablePage/predefined";
import { SexOpt } from "@/helpers/selection";
import { tableColsMixin } from "@/helpers/optionsMixin";
import { createTagVNode, createSwitchVNode } from "@/helpers/createVNode";

export default defineTableCols(() => [
  {
    label: "序号",
    minWidth: "50",
    type: "index",
    fixed: "left",
  },
  {
    label: "登录账号",
    minWidth: 100,
    prop: "accountNo",
    fixed: "left",
    showOverflowTooltip: true,
  },
  {
    label: "名字",
    minWidth: 100,
    prop: "name",
    fixed: "left",
    showOverflowTooltip: true,
  },
  {
    label: "性别",
    minWidth: 60,
    align: "center",
    prop: "sex",
    formatter: (_row, _column, cellValue: Sex) => {
      return SexOpt.getLabel(cellValue) || "-";
    },
  },
  {
    label: "手机号",
    minWidth: 100,
    prop: "phone",
    formatter: (_row, _column, cellValue: string) => {
      return cellValue || "-";
    },
  },
  {
    label: "部门",
    minWidth: 100,
    prop: "dept",
    formatter(_row, _column, cellValue: Dept) {
      return cellValue?.name || "-";
    },
  },
  {
    label: "角色",
    minWidth: 200,
    prop: "roles",
    formatter: (_row, _column, cellValue: Recordable<string>[]) => {
      return (
        cellValue?.map((role) =>
          createTagVNode(role.name, { type: "warning", effect: "plain" })
        ) || "-"
      );
    },
  },
  {
    label: "状态",
    minWidth: 80,
    prop: "status",
    formatter: (row, _column, cellValue: number) =>
      createSwitchVNode(cellValue, {
        activeValue: 1,
        inactiveValue: 0,
        activeText: "正常",
        inactiveText: "冻结",
        onChange: (newValue) => {
          row.status = newValue;
          console.log("switch 状态发生变化:", newValue);
        },
      }),
  },
  ...tableColsMixin,
  {
    label: "操作",
    fixed: "right",
    minWidth: 210,
    useRowBtns: true,
  },
]);
